package com.gw.smscheck.conf;

import com.gw.smscheck.security.sys.LogFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.Filter;

/**
 * 过滤器配置
 */
@Configuration
public class LogFilterConfig {

    @Bean
    public Filter characterEncodingFilter() {
        CharacterEncodingFilter c = new CharacterEncodingFilter();
        c.setEncoding("UTF-8");
        return c;
    }

    @Bean
    public FilterRegistrationBean contextFilterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(logFilter());//new LogFilter()这里不能这样使用,不然也会null
        registrationBean.addUrlPatterns("/*");//过滤路径
        registrationBean.setName("LogFilter");
        registrationBean.setOrder(1);//优先级
        return registrationBean;
    }

    @Bean
    public Filter logFilter() {
        return new LogFilter();
    }


}
